package com.angel.components.validators{
	import mx.collections.IList;
	import mx.validators.ValidationResult;

	public class NotRepeteadValidator extends BaseValidator {

		[Bindable]        
        public var dataProvider:IList;
        
        [Bindable]        
        public var attribute:String;

        public function NotRepeteadValidator() {
            super();
            super.modeValidate = "submit";
        }
   
        // Define the doValidation() method.
        override protected function doValidation(value:Object):Array {
			results = [];
			if(super.modeValidate == "edit"){
	            // Call base class doValidation().
	            results = super.doValidation(value);       
	       
				if(dataProvider == null || ( dataProvider != null && dataProvider.length == 0)){
					return results;
				}
				
				var currentValue:String = null;
				for each(var object:Object in dataProvider.toArray()){
					currentValue = object[attribute].toString();
					if(currentValue == value){
						results.push(new ValidationResult(true, null, "included", "Cannot repetead value '" + value + "'."));
					}
				}
			}
          
            return results;
        }
		
	}
}